package com.company;

import java.util.Random;
import java.util.Scanner;

// 双色球中奖
public class Test5 {
    public static void main(String[] args) {
        // 1、生成中奖号码
        int[] pcNumbers = createNumber();

        for (int i = 0; i < pcNumbers.length; i++) {
            System.out.print(pcNumbers[i] + " ");
        }

        // 2、用户输入数字
        int[] userNumbers = userInputNumbers();

        // 3、判断用户输入的球在不在中奖号码里面
        int redWinCount = 0;
        int blueWinCount = 0;

        for (int i = 0; i < pcNumbers.length - 1; i++) {

            for (int j = 0; j < userNumbers.length - 1; j++) {
                if (userNumbers[j] == pcNumbers[i]) {
                    redWinCount++;
                    // 找到以后可以直接跳出
                    break;
                }
            }
        }
        if (pcNumbers[pcNumbers.length - 1] == userNumbers[userNumbers.length - 1]) {
            blueWinCount++;
        }


        System.out.println("Red: " + redWinCount + " Blue: " + blueWinCount);

        // 4.开始设置金额池
        if (redWinCount == 6 && blueWinCount == 1) {
            System.out.println("You get ￥10,000,000");
        } else if (redWinCount == 6 && blueWinCount == 0) {
            System.out.println("You get ￥5,000,000");
        } else if ((redWinCount == 5 && blueWinCount == 1)) {
            System.out.println("You get ￥3,000");
        } else if ((redWinCount == 5 && blueWinCount == 0) || (redWinCount == 4 && blueWinCount == 1)) {
            System.out.println("You get ￥200");
        } else if ((redWinCount == 4 && blueWinCount == 0) || (redWinCount == 3 && blueWinCount == 1)) {
            System.out.println("You get ￥10");
        } else if ((redWinCount == 2 && blueWinCount == 1) || (redWinCount == 1 && blueWinCount == 1) || (redWinCount == 0 && blueWinCount == 1)) {
            System.out.println("You get ￥5");
        }

    }



    public static int[] userInputNumbers() {
        Scanner sc = new Scanner(System.in);
        int[] arr = new int[7];
        for (int i = 0; i < 6;) {
            // 如果下面不符合还会进入整个循环
            System.out.println("请输入第" + (i + 1) + "个红球" );
            int redNumber = sc.nextInt();
            if (redNumber >= 1 && redNumber <= 33) {
                if (!contains(arr, redNumber)) {
                    arr[i] = redNumber;
                    i++;
                } else {
                    System.out.println("当前红球已经存在，请重新输入");
                }
            } else {
                System.out.println("输入的红球已经超出了范围");
            }
        }

        System.out.println("请输入蓝色号码球");
        while (true) {
            int blueNumber = sc.nextInt();
            if (blueNumber >= 1 && blueNumber <= 16) {
                arr[arr.length - 1] = blueNumber;
                break;
            } else {
                System.out.println("当前篮球不符合规范");
            }
        }

        return arr;
    }

    public static int[] createNumber() {
        Random r = new Random();
        int[] arr = new int[7];
        for (int i = 0; i < 6;) {
            int redNumber = r.nextInt(33) + 1;
            if (!contains(arr, redNumber)) {
                arr[i] = redNumber;
                i++;
            }
        }

        int blueNumber = r.nextInt(16) + 1;
        arr[arr.length - 1] = blueNumber;


        return arr;
    }

    public static boolean contains(int[] arr, int number) {
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == number) {
                return true;
            }
        }
        return false;
    }


}
